<?php
namespace Api\Event\Thirdservice;

use Api\Event\BaseEvent;
use Common\Dto\BaseDto;

class ThirdserviceEvent extends BaseEvent
{
    public $app_id;

    final public static function instance($app_id)
    {
        $platform = D('Platform')->getByAppId($app_id);
        if (empty($platform)) {
            return null;
        }
        $name = 'Thirdservice/Thirdservice'.ucfirst($platform['app_code']);
        $event = event($name);

        if ($event instanceof ThirdserviceEvent){
            $event->app_id = $app_id;
            return $event;
        }else{
            return null;
        }
    }

    public function get($action, BaseDto $dto = null)
    {
        if(method_exists($this, $action)) {
            return $this->$action($dto);
        }
        return false;
    }
}